#include "IO.h"

ubyte* LoadEntireFile( const char* filename )
{
	FILE* f = fopen(filename, "rb");
	fseek(f, 0, SEEK_END);
	unsigned long size = ftell(f);
	fseek(f, 0, SEEK_SET);
	ubyte* buf = new ubyte[size+1];
	fread(buf, size, 1, f);
	fclose(f);
	buf[size] = 0;
	return buf;
}

void FileReader::Open(const char* f)
{
	mFile = fopen(f, "r");
}

int FileReader::ReadInt()
{
	int res = 0;
	fscanf((FILE*)mFile, "%i", &res);
	return res;
}

eastl::string FileReader::ReadLine()
{
	char buf[1024] = {0};
	fgets(buf, 1023, (FILE*)mFile);
	return buf;
}

eastl::string FileReader::ReadString()
{
	char buf[1024] = {0};
	fscanf((FILE*)mFile, "%1023s", buf);
	return buf;
}

void FileReader::Close()
{
	fclose((FILE*)mFile);
}